/**
 * 
 */
package model;

import java.util.ArrayList;

/**
 * This test class is a simple test of each functionality of the client.
 * @author alith
 */
public class Test {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			
			//connexion			
			CIMServer serv = new CIMServer("root/cimv2","http://localhost:5989","alith","password");
			
			
	//IPSecPolicy
			System.out.println("***************TEST IPSECPOLICY********************");
			IPSecPolicy exIPSecPolicy = new IPSecPolicy("lol", "192.168.1.100", "192.168.2.100", "any", "out", "ipsec", "", "", "esp", "transport", "require", serv);
			
			//enum
			ArrayList<IPSecPolicy> listIPSecPolicy = serv.enumIPSecPolicy();
			System.out.println("la y'a rien:");
			for (IPSecPolicy p : listIPSecPolicy) {
				System.out.println(p);
			}
			System.out.println();
			System.out.println("***");
			
			//creation
			serv.register(exIPSecPolicy);			
			listIPSecPolicy = serv.enumIPSecPolicy(); //verif grace a un enum
			System.out.println("la y'a une ligne:");
			for (IPSecPolicy p : listIPSecPolicy) {
				System.out.println(p);
			}
			System.out.println();
			System.out.println("***");
			
			//modification
			exIPSecPolicy.setType("ah");
			exIPSecPolicy.modify();
			listIPSecPolicy = serv.enumIPSecPolicy(); //verif grace a un enum
			System.out.println("la y'a pas la meme ligne:");
			for (IPSecPolicy p : listIPSecPolicy) {
				System.out.println(p);
			}
			System.out.println();
			System.out.println("***");
			
			//suppression
			serv.remove(exIPSecPolicy);
			listIPSecPolicy = serv.enumIPSecPolicy();//verif grace a un enum
			System.out.println("la y'a rien:");
			for (IPSecPolicy p : listIPSecPolicy) {
				System.out.println(p);
			}
			System.out.println();
			
	//IPSecRule
			System.out.println("***************TEST IPSECRULE********************");
			IPSecRule exIPSecRule = new IPSecRule("lol", "192.168.1.100", "192.168.2.100", "ah", "transport", "15700", "hmac-md5", "1234567890123456", serv);
			
			//enum
			ArrayList<IPSecRule> listIPSecRule = serv.enumIPSecRule();
			System.out.println("la y'a rien:");
			for (IPSecRule p : listIPSecRule) {
				System.out.println(p);
			}
			System.out.println();
			System.out.println("***");
			
			//creation
			serv.register(exIPSecRule);
			listIPSecRule = serv.enumIPSecRule(); //verif grace a un enum
			System.out.println("la y'a une ligne:");
			for (IPSecRule p : listIPSecRule) {
				System.out.println(p);
			}
			System.out.println();
			System.out.println("***");
			
			//modification
			exIPSecRule.setAlgorythm("3des-cbc");
			exIPSecRule.modify();
			listIPSecRule = serv.enumIPSecRule(); //verif grace a un enum
			System.out.println("la y'a pas la meme ligne:");
			for (IPSecRule p : listIPSecRule) {
				System.out.println(p);
			}
			System.out.println();
			System.out.println("***");
			
			//suppression
			serv.remove(exIPSecRule);
			listIPSecRule = serv.enumIPSecRule();//verif grace a un enum
			System.out.println("la y'a rien:");
			for (IPSecRule p : listIPSecRule) {
				System.out.println(p);
			}
			System.out.println();
			
			
	//IPTableRule
			System.out.println("***************TEST IPTABLERULE********************");
			IPTableRule exIPTableRule = new IPTableRule("lol","INPUT", "192.168.1.100", "192.168.2.100", "TCP", "80", "21", "ACCEPT", serv);
			
			//enum
			ArrayList<IPTableRule> listIPTableRule = serv.enumIPTableRule();
			System.out.println("la y'a rien:");
			for (IPTableRule p : listIPTableRule) {
				System.out.println(p);
			}
			System.out.println();
			System.out.println("***");
			
			//creation
			serv.register(exIPTableRule);
			listIPTableRule = serv.enumIPTableRule(); //verif grace a un enum
			System.out.println("la y'a une ligne:");
			//on recupere l'id...
			int aux = 0;
			for (IPTableRule p : listIPTableRule) {
				aux = p.getId();
				System.out.println(p);
			}
			System.out.println();
			System.out.println("***");
			
			//modification
			exIPTableRule.setId(aux);//normalement recupéré race aux ei...
			exIPTableRule.setChain("OUTPUT");
			exIPTableRule.modify();
			listIPTableRule = serv.enumIPTableRule(); //verif grace a un enum
			System.out.println("la y'a pas la meme ligne:");
			for (IPTableRule p : listIPTableRule) {
				System.out.println(p);
			}
			System.out.println();
			System.out.println("***");
			
			//suppression
			serv.remove(exIPTableRule);
			listIPTableRule = serv.enumIPTableRule();//verif grace a un enum
			System.out.println("la y'a rien:");
			for (IPTableRule p : listIPTableRule) {
				System.out.println(p);
			}
			System.out.println();
		}catch (Exception e) {
			e.printStackTrace();
		}

	}

}
